var ns, toast, UIActionProgress, UISearchBar;
var app = new Vue({
    el: '#app',
    data: {
        companyName: '', //公司名称
        postionName: "", //岗位
        userHeadImg: "", //用户头像
        userName: "", //用户名称
        bannerimg: '../image/header_bg.png',
        IsMain:1,
        list: [],
        TypeID:0,
        IsShow:false,
        form: {
            pageindex: 0,
            pagesize: 2,
        },
        showsearch:false,
        showTop:false,
        name:'',
        typeurl:'',
        moduleList:[],
        touchID:0,
        SortOrder:0,
        newCount:5,//消息未读数量
        choosetypemodel:{},
        choosetypechildren:{},
        choosetaskmodel:{},
        choosesortmodel:{},
        option1: [
            {ID:0, text: '全部', value: 0 },
            {ID:814, text: '报事报修', value: 1 },
            {ID:690, text: '设备管理', value: 2 },
            {ID:963, text: '内部通知', value: 3 },
            {ID:956, text: '审批申请', value: 4 },
        ],
        optionChildren: [
            { count:20,text: '全部分类', value: 0 },
            { count:5,text: '报事报修', value: 1 },
            { count:6,text: '设备管理', value: 2 },
            { count:7,text: '内部通知', value: 3 },
        ],
        option2: [
            { count:20,text: '全部任务', value: 0 },
            { count:5,text: '进行中', value: 1 },
            { count:6,text: '我发起的', value: 2 },
            { count:7,text: '我参与的', value: 3 },
            { count:3,text: '已完成', value: 4 },
        ],
        option3: [
            // { text: '排序', value: 0 },
            { text: '按任务发布时间远到近', value: 1 },
            { text: '按任务发布时间近到远', value: 2 },
        ],
        imglist: [
            { local_id: 'http://demo.saasyy.com/upload/ZhuangXiu/20200904/132436810283341358.jpg', media_id: '0' },
            { local_id: 'http://demo.saasyy.com/upload/ZhuangXiu/20200904/132436810283341358.jpg', media_id: '1' },
        ],
    },
    methods: {
        get_data: function () {
            var that = this;
            that.choosetaskmodel=that.option2[0];
            that.choosetypemodel=that.option1[0];
            that.choosetypechildren=that.optionChildren[0];
            that.choosesortmodel=that.option3[0];
            // var options = {};
            // options.action = "getsysmenulist";
            // options.IsMain=that.IsMain;
            // ns.post(options, function (succeed, data, err) {
            //     if (succeed) {
            //         if (data.postionName) that.postionName = data.postionName; 
            //         if(data.list.length>0){
            //             that.list=data.list;
            //         }
            //         for(var i=0;i<data.list.length;i++){
            //             if(data.list[i].AddTime){
            //                 data.list[i].AddTime = ns.SetTime_style(data.list[i].AddTime);
            //             }else{
            //                 data.list[i].AddTime='';
            //             }
                        
            //         }
                    
            //     } 
            // });
        },
        onChooseType:function(item){
            var that = this;
            that.choosetypemodel=item;
            // that.optionChildren=list;//重新赋值
            that.choosetypechildren={};
            if(that.optionChildren.length>0){
                that.choosetypechildren=that.optionChildren[0]
            }
        },
        onChooseTypeChildren:function(item){
            var that = this;
            that.choosetypechildren=item;
            this.$refs.choosetype.toggle();
        },
        onChooseTask:function(item){
            var that = this;
            that.choosetaskmodel=item;
            this.$refs.choosetask.toggle();
        },
        onChooseSort:function(item){
            var that = this;
            that.choosesortmodel=item;
            this.$refs.choosesort.toggle();
        },
        get_user_data: function () {
            var that = this;
            // 公司名称
            var companyName = api.getPrefs({
                sync: true,
                key: 'companyName'
            });
            // 岗位名称
            var positionname = api.getPrefs({
                sync: true,
                key: 'positionname'
            });
            // 用户名称
            var username = api.getPrefs({
                sync: true,
                key: 'username'
            });
            // 用户头像
            var headimg = api.getPrefs({
                sync: true,
                key: 'headimg'
            });
            that.companyName = companyName || '重庆永友网络科技有限公司';
            that.postionName = positionname ? positionname : "";
            that.userHeadImg = headimg || '../image/default.png';
            that.userName = username || '匿名用户';
        },
        do_open_scan_login: function (item) {
            var that = this;
            ns.confirmPer('camera', function () {
                setTimeout(function () {
                    that.do_open_scan_login_start();
                }, 200)
            })
        },
        do_open_scan_login_start: function () {
            var that = this;
            ns.openFrame('scanner_frm', {
                type: 0
            });
        },
        //点击遮罩关闭弹窗
        doHideSearch:function(){
            var that=this;
            that.showsearch = false;
            that.showTop=false;
            that.IsMain=1;
            that.get_data();
        },   
        //打开个人中心
        openSetting: function () {
            ns.openWin('gerenzhongxin_frm', '个人信息');
        },
        //打开搜索
        do_open_sousuo:function(){
            ns.openWin('home_sousuo', '搜索中心');
        },
         //打开消息中心
        do_open_news:function(){
            ns.openWin('home_news_center', '消息中心');
        },
    }
});
apiready = function () {
    api.parseTapmode();
    ns = window.Foresight.Util;
    UIActionProgress = api.require('UIActionProgress');
    
    toast = new auiToast();
    setTimeout(function () {
        app.get_data();
    }, 500);
    setTimeout(function () {
        appupgrade.check_upgrade(false);
    }, 5000)
    ns.init_pull(true);
    app.get_user_data();
    api.addEventListener({
        name: 'changecentersuccess'
    }, function () {
        app.get_user_data();
    });
    
    api.addEventListener({
        name: 'isreadtrue'
    }, function (ret, err) {
        if (ret) {
            setTimeout(function () {
                app.get_data();
            }, 500);
        } else {
            api.toast({
                msg: err,
                duration: 2000,
                location: 'bottom'
            });
        }
    });
    api.addEventListener({
        name: 'isreadCustomer'
    }, function () {
        app.get_data();
    });
    api.addEventListener({
        name: 'isreadEquipment'
    }, function () {
        app.get_data();
    });
    api.addEventListener({
        name: 'isreadPatrol'
    }, function () {
        app.get_data();
    });
    api.addEventListener({
        name: 'isreadBjlh'
    }, function () {
        app.get_data();
    });
    api.addEventListener({
        name: 'isreadTongzhi'
    }, function () {
        app.get_data();
    });
    api.addEventListener({
        name: 'isreadExamine'
    }, function () {
        app.get_data();
    });
    api.addEventListener({
        name: 'home_new_updata'
    }, function () {
        app.get_data();
    });
    api.addEventListener({
        name: 'purchase_updata'
    }, function () {
        app.get_data();
    });
}
